package com.kungfuhacking.wristbandpro.location.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.kungfuhacking.wristbandpro.R;
import com.kungfuhacking.wristbandpro.base.view.BaseActivity;
import com.kungfuhacking.wristbandpro.custom.EnterItemView;
import com.kungfuhacking.wristbandpro.custom.TitleBarView;
import com.kungfuhacking.wristbandpro.location.bean.OldEntity;

/**
 * 手表设置
 * Created by Aaron on 17/4/20.
 */

public class WristbandSettingActivity extends BaseActivity implements View.OnClickListener {

    private android.widget.TextView tvnickname;
    private android.widget.TextView tvsn;
    private android.widget.TextView tvelectricquantity;
    private android.widget.TextView tvsign;
    private android.widget.TextView tvaddress;
    private TitleBarView tbv_title;
    private EnterItemView etv_tel;
    private String TAG = getClass().getSimpleName();
    private OldEntity oldEntity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_wristband_setting);

        initWidget();

        if (bundle != null) {
            oldEntity = bundle.getParcelable("oldEntity");
        }

        setInfo();
    }

    private void initWidget() {
        tbv_title = (TitleBarView) findViewById(R.id.tbv_title);
        etv_tel = (EnterItemView) findViewById(R.id.etv_tel);
        this.tvaddress = (TextView) findViewById(R.id.tv_address);
        this.tvsign = (TextView) findViewById(R.id.tv_sign);
        this.tvelectricquantity = (TextView) findViewById(R.id.tv_electric_quantity);
        this.tvsn = (TextView) findViewById(R.id.tv_sn);
        this.tvnickname = (TextView) findViewById(R.id.tv_nickname);


        tbv_title.setOnLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        etv_tel.setOnClickListener(this);
    }


    private void setInfo() {

        if (oldEntity == null)
            return;

        tvnickname.setText(oldEntity.getName() + (oldEntity.getDevice().isOnline() ? " (在线)" : " (离线)"));
        etv_tel.setRightTxt(oldEntity.getDevice().getPhoneNum());
        tvelectricquantity.setText(oldEntity.getDevice().getBattery() + "%");
        tvsign.setText(oldEntity.getDevice().getGsm() + "%");
        tvaddress.setText(oldEntity.getDevice().getLocation());
        tvsn.setText(oldEntity.getDevice().getSn());

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.etv_tel:

                if (oldEntity == null)
                    return;

                Intent intent = new Intent(this, ModifyWritbandTelActivity.class);
                intent.putExtra("id", oldEntity.getId());
                startActivityForResult(intent, 10033);
                break;

        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (data == null)
            return;

        if (requestCode == 10033 && resultCode == 10034)
            etv_tel.setRightTxt(data.getStringExtra("tel"));

    }
}
